#include "Movement.h"

#include "World/Player.h"
#include "Physics/AABB.h"

bool Movement::CanMove(const glm::vec3 &from, const glm::vec3 &to, World &world)
{
  glm::vec3 movementDirection = glm::normalize(from - to);

  AABB playerAABBCopy = Player::PlayerAABB;
  playerAABBCopy.minPoint += to;
  playerAABBCopy.maxPoint += to;

  for (auto point : Player::PlayerBoundingBox)
  {
    point += to;
    if (WorldRayCast ray{point, movementDirection, 3.0f, world})
    {
      glm::vec3 position = ray.GetHitTarget().blockPosition;

      if (AABB::FromBlockPosition(position).Intersect(playerAABBCopy))
      {
        return false;
      }
    }
  }

  return true;
}